import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.*;

public class CalendarDialog extends JDialog 
{
	public CalendarDialog(JFrame frame)
	{
		super(frame,Resources.getString("selectDate"),true);
		isSelectedDate = false;
		year = new CalendarGraphic();
		this.add(year.getPanel(),BorderLayout.CENTER);
		this.add(getPanelSouth(),BorderLayout.SOUTH);
		this.setSize(300, 300);
		this.setResizable(false);
	}
	public CalendarDialog(JFrame frame,Date selectDate)
	{
		super(frame,Resources.getString("selectDate"),true);
		isSelectedDate = false;
		year = new CalendarGraphic(selectDate);
		this.add(year.getPanel(),BorderLayout.CENTER);
		this.add(getPanelSouth(),BorderLayout.SOUTH);
		this.setSize(300, 300);
		this.setResizable(false);
	}
	private JPanel getPanelSouth()
	{
		JButton okButton = new JButton(Resources.getString("ok"));
		okButton.addActionListener(new 
				ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{				
						if(year.getSelectedDays() != null)
						{
							isSelectedDate = true;
							setVisible(false);
						}
					}
				}
		);
		JButton cancelButton = new JButton(Resources.getString("cancel"));
		cancelButton.addActionListener(new 
				ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{				
						setVisible(false);
					}
				}
		);
		JPanel panelSouth = new JPanel();
		panelSouth.add(okButton);
		panelSouth.add(cancelButton);
		return panelSouth;
	}
	public boolean existSelectedDate()
	{
		return isSelectedDate;
	}
	public Date[] getSelectedDays()
	{
		return year.getSelectedDays();
	}
	public void setDaysMarked(Date[] days)
	{
		year.setDaysMarked(days);
	}
	public void setSelectedDays(Date[] days)
	{
		year.setSelectedDays(days);
	}
	public void setNormalSelectionMode(boolean mode)
	{
		year.setNormalSelectionMode(mode);
	}
	public void setSingleSelection(boolean type) 
	{
		year.setSingleSelection(type);
	}
	private CalendarGraphic year;
	private boolean isSelectedDate;
}
